#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <SDL.h>

int
main(int argc,char**argv)
{
	assert (SDL_Init(SDL_INIT_VIDEO|// need video for events
			 SDL_INIT_JOYSTICK) == 0);
	atexit(SDL_Quit);

	SDL_Joystick * joy = NULL;
	if(SDL_NumJoysticks()>0){
		joy = SDL_JoystickOpen(0);
		SDL_JoystickEventState(SDL_ENABLE);
	}
	assert(joy);

	while(1) {
		SDL_Event ev;
		while(SDL_PollEvent(&ev)) {
			switch(ev.type) {
			case SDL_KEYDOWN:
				switch(ev.key.keysym.sym) {
				case SDLK_ESCAPE:
					exit(0);
					break;
				}
				break;
			case SDL_JOYAXISMOTION:
				printf("jaxis: which=%u axis=%u value=%d\n", ev.jaxis.which, ev.jaxis.axis, ev.jaxis.value);
				break;
			}
		}
	}
}

